-- FETCH_PROP_RANDOM_BONUS

-- 抽取prop属性获得的随机物品奖励
-- @param key 辨识需求的道具类型
return function(key)
    -- 默认给个烤肉，防报错
    local classId = 7001;
    local arr;
    local rand = DungeonM.getRandSeed("FETCH_PROP_RANDOM_BONUS");

    if key == "component_1" then
        -- 获取所在迷宫id
        local dungeonId = DungeonM.getDungeonId();
        dungeonId = DungeonAreaM.getParentId(dungeonId);

        -- 下楼随机获得工程元件：爆破元件、生化元件、冶金元件、古代元件，比例为3:3:3:1
        arr = { { ["classId"] = 7516, ["ratio"] = 30 }, { ["classId"] = 7517, ["ratio"] = 30, },
                { ["classId"] = 7518, ["ratio"] = 30 }, { ["classId"] = 7522, ["ratio"] = 10, }, };

        if dungeonId == 1003 then
            arr = { { ["classId"] = 7519, ["ratio"] = 30 }, { ["classId"] = 7520, ["ratio"] = 30, },
                    { ["classId"] = 7521, ["ratio"] = 30 }, { ["classId"] = 7522, ["ratio"] = 10, }, };
        end

        -- 抽取一种物品
        classId = fetchElemBySeed(arr, rand)["classId"];
    elseif key == "jewel" then
        -- 随机获得宝石
        -- 红宝石、蓝宝石、猫眼石，权重80，无限制
        arr = { { ["classId"] = 7609, ["ratio"] = 80, },
                { ["classId"] = 7610, ["ratio"] = 80, },
                { ["classId"] = 7611, ["ratio"] = 80, }, };

        -- 黄晶石、青金石、石榴石、绿松石，权重100
        -- 过滤一遍次数限制
        local fetchList = { 7612, 7613, 7614, 7615};
        for _, id in ipairs(fetchList) do
            if not DungeonServiceM.isStatItemLimit(id) then
                table.insert(arr, { ["classId"] = id, ["ratio"] = 100, });
            end
        end

        -- 处刑者黑钻、法则之石、灾厄之星、王冠之钻，权重20，一次迷宫只能出现其中一个
        -- 其中王冠之钻一辈子限制三次
        fetchList = { 8273, 8274, 8275}
        if BuffDataM.query("limited_gem", 6) < 3 then
            table.insert(fetchList, 8276);
        end

        -- 没有获得过，则加入抽取
        local hadAppear = false;
        for _, id in ipairs(fetchList) do
            if DungeonServiceM.isStatItemLimit(id) then
                hadAppear = true;
                break;
            end
        end
        if not hadAppear then
            for _, id in ipairs(fetchList) do
                table.insert(arr, { ["classId"] = id, ["ratio"] = 20, });
            end
        end

        -- 抽取一种
        classId = fetchElemBySeed(arr, rand)["classId"];
    elseif key == 7529 then
        -- 从三个里等权重抽取一个
        arr = { 7516, 7517, 7518, };

        classId = FormulaM.invoke("FETCH_BY_RAND", arr, rand);
    elseif key == 7530 then
        classId = 7522;
    end

    return classId;
end
